package com.example.basic.web.controller.report;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.warn.DepotWarn;
import com.example.basic.web.request.DepotQueryRequest;
import com.example.basic.web.response.report.InOutRecordResponse;
import com.example.basic.web.response.report.StockCountResponse;
import com.example.basic.web.service.report.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Api(value  = "存储数据查询", tags = {"存储数据查询"})
@RestController
@RequestMapping("/api/v1/byg/report")
public class ReportController {

    @Resource
    private ReportService reportService;


    @Log(title = "存储数据查询", description = "库存信息查询")
    @ApiOperation(value = "库存信息查询", notes = "库存信息查询")
    @PostMapping("/queryStockInfo")
    public Result<IPage<StockCountResponse>> queryStockInfo(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<StockCountResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(reportService.queryStockInfo(queryPage,searchParam, pharmCode,zoneCode,depotCode));
    }

    @Log(title = "存储数据查询", description = "库存信息统计")
    @ApiOperation(value = "库存信息统计", notes = "库存信息统计")
    @PostMapping("/stockCount")
    public Result<Map> stockCount(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode) {
        return ResultGenerator.genSuccessResult(reportService.stockCount(searchParam,pharmCode,zoneCode,depotCode));
    }

    @Log(title = "存储数据查询", description = "出入库记录查询")
    @ApiOperation(value = "出入库记录查询", notes = "出入库记录查询")
    @PostMapping("/queryInOutRecord")
    public Result<IPage<InOutRecordResponse>> queryInOutRecord(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "type", value = "出入库类型 0-全部,1-入库,2-出库") @RequestParam(defaultValue = "0") String type,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<InOutRecordResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(reportService.queryInOutRecord(queryPage,searchParam, pharmCode,zoneCode,depotCode,beginTime,endTime,type));
    }

    @Log(title = "存储数据查询", description = "出入库记录统计")
    @ApiOperation(value = "出入库记录统计", notes = "出入库记录统计")
    @PostMapping("/InOutRecordCount")
    public Result<Map> InOutRecordCount(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "type", value = "出入库类型 0-全部,1-入库,2-出库") @RequestParam(defaultValue = "0") String type) {
        return ResultGenerator.genSuccessResult(reportService.InOutRecordCount(searchParam,pharmCode,zoneCode,depotCode,beginTime,endTime,type));
    }

    @Log(title = "存储数据查询", description = "库位信息查询")
    @ApiOperation(value = "库位信息查询", notes = "库位信息查询")
    @PostMapping("/queryDepotInfo")
    public Result<IPage<StockCountResponse>> queryDepotInfo(
            @ApiParam(name = "depotQueryRequest", value = "库位查询条件") @RequestBody DepotQueryRequest depotQueryRequest) {
        Page<StockCountResponse> queryPage = new Page<>(depotQueryRequest.getPage(),depotQueryRequest.getSize());
        return ResultGenerator.genSuccessResult(reportService.queryDepotInfo(queryPage,depotQueryRequest));
    }

    @Log(title = "存储数据查询", description = "库位信息统计")
    @ApiOperation(value = "库位信息统计", notes = "库位信息统计")
    @PostMapping("/depotCount")
    public Result<Map> depotCount(
            @ApiParam(name = "depotQueryRequest", value = "库位统计条件") @RequestBody DepotQueryRequest depotQueryRequest) {
        return ResultGenerator.genSuccessResult(reportService.depotCount(depotQueryRequest));
    }

    @Log(title = "统计报表管理", description = "库存汇总报表")
    @ApiOperation(value = "库存汇总报表", notes = "库存汇总报表")
    @PostMapping("/stockSumReport")
    public Result<Map> stockSumReport(
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode) {
        return ResultGenerator.genSuccessResult(reportService.stockSumReport(pharmCode,zoneCode));
    }

    @Log(title = "统计报表管理", description = "库存明细报表")
    @ApiOperation(value = "库存明细报表", notes = "库存明细报表")
    @PostMapping("/stockDetailReport")
    public Result<Map> stockDetailReport(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "status", value = "状态 0-全部 1-占用，2-空闲") @RequestParam(defaultValue = "0") String status) {
        return ResultGenerator.genSuccessResult(reportService.stockDetailReport(searchParam,pharmCode,zoneCode,depotCode,status));
    }

    @Log(title = "统计报表管理", description = "出入库记录报表")
    @ApiOperation(value = "出入库记录报表", notes = "出入库记录报表")
    @PostMapping("/InOutRecordReport")
    public Result<Map> InOutRecordReport(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "type", value = "出入库类型 0-全部,1-入库,2-出库") @RequestParam(defaultValue = "0") String type) {
        return ResultGenerator.genSuccessResult(reportService.InOutRecordReport(searchParam, pharmCode,zoneCode,depotCode,beginTime,endTime,type));
    }

    @Log(title = "统计报表管理", description = "库位信息报表")
    @ApiOperation(value = "库位信息报表", notes = "库位信息报表")
    @PostMapping("/depotInfoReport")
    public Result<Map> depotInfoReport(
            @ApiParam(name = "depotQueryRequest", value = "库位查询条件") @RequestBody DepotQueryRequest depotQueryRequest) {
        return ResultGenerator.genSuccessResult(reportService.depotInfoReport(depotQueryRequest));
    }

    @Log(title = "统计报表管理", description = "库存预警报表")
    @ApiOperation(value = "库存预警报表", notes = "库存预警报表")
    @PostMapping("/depotWarnReport")
    public Result<Map> depotWarnReport(
            @ApiParam(name = "pharmCode", value = "仓库编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode) {
        return ResultGenerator.genSuccessResult(reportService.depotWarnReport(pharmCode, zoneCode));
    }

    @Log(title = "首页", description = "设备情况")
    @ApiOperation(value = "首页-设备情况", notes = "首页-设备情况")
    @PostMapping("/homeDeviceReport")
    public Result<List<Map>> homeDeviceReport() {
        return ResultGenerator.genSuccessResult(reportService.homeDeviceReport());
    }

    @Log(title = "首页", description = "今日数量统计")
    @ApiOperation(value = "首页-今日数量统计", notes = "首页-今日数量统计")
    @PostMapping("/homeRemainsCount")
    public Result<Map> homeRemainsCount() {
        return ResultGenerator.genSuccessResult(reportService.homeRemainsCount());
    }

    @Log(title = "首页", description = "库位安全预警")
    @ApiOperation(value = "首页-库位安全预警", notes = "首页-库位安全预警")
    @PostMapping("/homeDepotWarn")
    public Result<Integer> homeDepotWarn() {
        return ResultGenerator.genSuccessResult(reportService.homeDepotWarn());
    }

    @Log(title = "首页", description = "特殊环节占比")
    @ApiOperation(value = "首页-特殊环节占比", notes = "首页-特殊环节占比")
    @PostMapping("/homeSpecialCount")
    public Result<Map> homeSpecialCount(
            @ApiParam(name = "isAll", value = "1-今日，2-历史") @RequestParam String isAll) {
        return ResultGenerator.genSuccessResult(reportService.homeSpecialCount(isAll));
    }

    @Log(title = "首页", description = "出入库作业执行情况")
    @ApiOperation(value = "首页-出入库作业执行情况", notes = "首页-出入库作业执行情况")
    @PostMapping("/homeInstructCount")
    public Result<List<Map>> homeInstructCount() {
        return ResultGenerator.genSuccessResult(reportService.homeInstructCount());
    }

    @Log(title = "首页", description = "库位统计对比情况")
    @ApiOperation(value = "首页-库位统计对比情况", notes = "首页-库位统计对比情况")
    @PostMapping("/homeDepotCount")
    public Result<List<Map>> homeDepotCount(
            @ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam String pharmCode) {
        return ResultGenerator.genSuccessResult(reportService.homeDepotCount(pharmCode));
    }

    @Log(title = "首页", description = "近一周火化，入馆统计")
    @ApiOperation(value = "首页-近一周火化，入馆统计", notes = "首页-近一周火化，入馆统计")
    @PostMapping("/homeWeekCount")
    public Result<Map> homeWeekCount() {
        return ResultGenerator.genSuccessResult(reportService.homeWeekCount());
    }
}
